package com.iplant.pdm.serviceImpl;

import com.iplant.base.po.OutResult;
import com.iplant.base.po.Pagination;
import com.iplant.base.po.ServiceResult;
import com.iplant.base.po.enums.ExceptionTypes;
import com.iplant.basic.service.po.bms.BMSEmployee;
import com.iplant.basic.serviceImpl.BMSServiceImpl;
import com.iplant.pdm.service.PDMFMCService;
import com.iplant.pdm.service.po.fmc.FMCLine;
import com.iplant.pdm.serviceImpl.dao.fmc.FMCLineDAO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class PDMFMCServiceImpl implements PDMFMCService {
	private static Logger logger = LoggerFactory.getLogger(BMSServiceImpl.class);

	public PDMFMCServiceImpl() {
		// TODO Auto-generated constructor stub
	}

	private static PDMFMCService Instance = null;

	public static PDMFMCService getInstance() {
		if (Instance == null)
			Instance = new PDMFMCServiceImpl();

		return Instance;
	}

	//region 产线

	@Override
	public ServiceResult<Integer> FMC_UpdateLine(BMSEmployee wLoginUser, FMCLine wLine) {
		ServiceResult<Integer> wResult = new ServiceResult<Integer>();
		try {
			OutResult<Integer> wErrorCode = new OutResult<Integer>();
			wErrorCode.set(0);
			FMCLineDAO.getInstance().FMC_UpdateLine(wLoginUser, wLine, wErrorCode);
			wResult.FaultCode += ExceptionTypes.getEnumType(wErrorCode.get()).getLabel();

		} catch (Exception e) {
			wResult.FaultCode += e.toString();
			logger.error(e.toString());
		}
		return wResult;
	}

	@Override
	public ServiceResult<Integer> FMC_DeleteLine(BMSEmployee wLoginUser, FMCLine wLine) {
		ServiceResult<Integer> wResult = new ServiceResult<Integer>();
		try {
			OutResult<Integer> wErrorCode = new OutResult<Integer>();
			FMCLineDAO.getInstance().DeletePO(wLoginUser, wLine, wErrorCode);
			wResult.FaultCode += ExceptionTypes.getEnumType(wErrorCode.get()).getLabel();

		} catch (Exception e) {
			wResult.FaultCode += e.toString();
			logger.error(e.toString());
		}
		return wResult;
	}

	@Override
	public ServiceResult<Integer> FMC_ActiveLine(BMSEmployee wLoginUser, FMCLine wLine, int wActive) {
		ServiceResult<Integer> wResult = new ServiceResult<Integer>();
		try {
			OutResult<Integer> wErrorCode = new OutResult<Integer>();
			FMCLineDAO.getInstance().FMC_ActiveLine(wLoginUser, wLine, wActive, wErrorCode);
			wResult.FaultCode += ExceptionTypes.getEnumType(wErrorCode.get()).getLabel();

		} catch (Exception e) {
			wResult.FaultCode += e.toString();
			logger.error(e.toString());
		}
		return wResult;
	}

	@Override
	public ServiceResult<FMCLine> FMC_QueryLine(BMSEmployee wLoginUser, int wID, String wCode) {
		ServiceResult<FMCLine> wResult = new ServiceResult<FMCLine>();
		try {
			OutResult<Integer> wErrorCode = new OutResult<Integer>();
			wErrorCode.set(0);
			wResult.Result = FMCLineDAO.getInstance().FMC_QueryLine(wLoginUser, wID, wCode, wErrorCode);
			wResult.FaultCode += ExceptionTypes.getEnumType(wErrorCode.get()).getLabel();

		} catch (Exception e) {
			wResult.FaultCode += e.toString();
			logger.error(e.toString());
		}
		return wResult;
	}

	@Override
	public ServiceResult<List<FMCLine>> FMC_QueryLineList(BMSEmployee wLoginUser, int wFactoryID, String wName,
														  int wActive, Pagination wPagination) {
		ServiceResult<List<FMCLine>> wResult = new ServiceResult<List<FMCLine>>();
		try {
			OutResult<Integer> wErrorCode = new OutResult<Integer>();
			wErrorCode.set(0);
			wResult.Result = FMCLineDAO.getInstance().FMC_QueryLineList(wLoginUser, wFactoryID, wName, wActive,
					wPagination, wErrorCode);
			wResult.FaultCode += ExceptionTypes.getEnumType(wErrorCode.get()).getLabel();

		} catch (Exception e) {
			wResult.FaultCode += e.toString();
			logger.error(e.toString());
		}
		return wResult;
	}

	//endregion

}
